package com.example.my_self_view.list2

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.my_self_view.databinding.ActivityList2Binding

class List2Activity: AppCompatActivity(), LetterSideBar.TouchLetterListener {

    private lateinit var mBinding: ActivityList2Binding
    private val mHandler = Handler(Looper.getMainLooper())
    private lateinit var runnable: Runnable

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityList2Binding.inflate(layoutInflater)
        setContentView(mBinding.root)

        mBinding.letterSideBar.setTouchLetterListener(this)

        runnable = Runnable { mBinding.letterTv.visibility = View.GONE }
    }

    override fun touch(letter: String) {
        mBinding.letterTv.visibility = View.VISIBLE
        mBinding.letterTv.text = letter
    }

    override fun up() {
        // 可以在这里加个延迟消失
        mHandler.removeCallbacks(runnable)
        mHandler.postDelayed(runnable, 200)
    }
}